package classification.calcSimilarity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

import classification.Dictionary;
import classification.elemListRepr.ElemListReprGenerator;
import classification.elemListRepr.XMLElementList;

import preprocess.DBWrapper;
import preprocess.XMLDoc;

import similarity.Similarity;

import static utils.Configuration.*;

/**
 * 提供XML文档相似度计算的抽象类
 * 
 * @author eDisOn
 * 
 */
public abstract class CalcSimilarity implements Similarity
{
    private static final String                        ROOT             = RootPath;
    protected HashMap<String, HashMap<String, Double>> similarityRecord = null;

    protected ElemListReprGenerator                    ELRGenerator     = null;

    private HashMap<String, XMLElementList>            List             = null;

    public CalcSimilarity()
    {
        List = new HashMap<String, XMLElementList>();
        similarityRecord = new HashMap<String, HashMap<String, Double>>();
        ELRGenerator = new ElemListReprGenerator();
        ELRGenerator.loadXMLEListTemplate();
    }

    protected XMLElementList loadXMLEList(XMLDoc doc)
    {
        /*
         * 首先判断该XMLDoc是否已经经过了XMLElementList转化的预处理， 如果是就直接从内存中导入，否则就进行转化，并保存到内存中
         */
        String docID = doc.getDocID();
        if (this.List.containsKey(docID))
        {
            return this.List.get(docID);
        }
        else
        {
            XMLElementList xmlElemList = this.ELRGenerator.XMLELReprGenerator(
                    doc.getDoc(), docID);
            this.List.put(docID, xmlElemList);// 做备忘录
            return xmlElemList;
        }
    }
}
